package com.sti.platform.dao.impl;

import com.aisino.core.dao.BaseDao;
import com.aisino.tools.enums.PageEnum;
import com.aisino.tools.enums.QlEnum;
import com.aisino.tools.util.page.Page;
import com.sti.platform.dao.SysLogDao;
import com.sti.platform.model.SysLog;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class SysLogDaoImpl extends BaseDao implements SysLogDao{

	/**不加任何条件获取全部数据*/
	@Override
	public List<SysLog> getAllSysLog() {
		String sql = " SELECT * FROM sys_log ";
		return super.getBySql(sql,SysLog.class);
	}
	/**带条件获取数据*/
	@SuppressWarnings("unchecked")
	@Override
	public List<SysLog> getSysLogByParam(String sql, String[] params, Object[] values) {
		return super.getBySql(sql, params, values, SysLog.class);
	}

	/**
	 * 获取全部 条数
	 */
	@Override
	public Integer getAllSysLogNum() {
		return super.getTotalCount(" SELECT * FROM sys_log ", null, null, QlEnum.SQL);
	}


	@Override
	/**
	 * 根据条件获取条数
	 */
	public Integer getSysLogNum(String sql,String[] params, Object[] values){
		return super.getTotalCount(sql, params, values, QlEnum.SQL);
	}

	/**根据条件 分页获取 数据*/
	@Override
	public List<SysLog> getSysLogByPage(String qlString, String[] params, Object[] values, Integer top,
										Page pageModel,  QlEnum qlType, PageEnum pageType) {
		Page page = super.getByHibernateQuery(qlString, params, values, top, pageModel, SysLog.class, QlEnum.SQL, pageType);
		return page.getRecord();
	}

	/**根据ID 获取单个数据*/
	@Override
	public SysLog getSysLogByID(String id) {
		return super.get(SysLog.class, id);
	}

	/**保存*/
	@Override
	public String saveSysLog(SysLog SysLog) {
		return super.save(SysLog);
	}

	/**删除*/
	@Override
	public Integer delSysLog(String id) {
		String sql = "DELETE FROM sys_log WHERE id = '"+ id +"' ";
		return super.executeQL(sql, new String[]{}, new Object[]{}, QlEnum.SQL);
	}

	/**删除*/
	@Override
	public Integer delSysLog(String ids[]) {
		String delIds = "";
		if(ids.length>0){
			for(String id : ids){
				delIds += "'"+id+"',";
			}
			delIds = delIds.substring(0,(delIds.length()));
		}
		delIds = delIds.substring(0,(delIds.length()-1));
		String sql = "DELETE FROM sys_log WHERE id in ("+ delIds +") ";
		return super.executeQL(sql, new String[]{}, new Object[]{}, QlEnum.SQL);
	}

	/**修改*/
	@Override
	public String updateSysLog( SysLog SysLog) {
		return super.update(SysLog);
	}


}
